package com.doit.demo03;

import java.io.*;

//GBK文件转换为utf-8文件
public class test01 {
    public static void main(String[] args) throws IOException {
        Reader gbk = new InputStreamReader(new FileInputStream("d:\\work\\编码\\编码GBK.txt"), "GBK");
        Writer out = new OutputStreamWriter(new FileOutputStream("d:\\work\\编码\\utf_8.txt"));

        int len;
        char[] chars = new char[1024];
        while ((len=gbk.read(chars))!=-1){
            out.write(chars,0,len);
            out.flush();
        }

        out.close();
        gbk.close();
//        method();
    }
    public static void method() throws IOException {
        Reader in = new InputStreamReader(new FileInputStream("d:\\work\\编码\\编码GBK.txt"),"utf-8");
        Writer out = new OutputStreamWriter(new FileOutputStream("d:\\work\\编码\\gbk.txt"));

        int len;
        char[] chars = new char[1024];
        while ((len=in.read(chars))!=-1){
            out.write(chars,0,len);
            out.flush();
        }

//        out.close();
//        in.close();
//        Reader in2 = new InputStreamReader(new FileInputStream("d:\\work\\编码\\gbk.txt"),"gbk");
//        int len2;
//        char[] chars2 = new char[1024];
//        while ((len2=in2.read(chars2))!=-1){
//            System.out.println(new String(chars,0,len2));
//        }

    }
}
